package com.qyhl.module_activities.act.player.list;


import com.qyhl.webtv.commonlib.entity.act.PlayerVOBean;

import java.util.List;

/**
 * Created by qyhl2 on 2018/1/11.
 */

public class PlayerListPresenter implements PlayerListContract.PlayerListPresenter {

    private final PlayerListContract.PlayerListView mView;
    private final PlayerListModel mModel;

    public PlayerListPresenter(PlayerListContract.PlayerListView view) {
        mView = view;
        mModel = new PlayerListModel(this);
    }

    @Override
    public void onError(int i, String string) {
        if (i == 1) {
            mView.onError(string);
        } else if (i == 2) {
            mView.onVoteError(string);
        } else if (i == 3) {
            mView.onSearchError(string);
        }
    }

    @Override
    public void onSuccess(List<PlayerVOBean> data, String page) {
        if (data == null || data.size() == 0) {
            if (page.equals("1")) {
                mView.onEmpty();
            } else {
                mView.notData();
            }
        } else {
            mView.onSuccess(data);
        }
    }

    @Override
    public void getData(String actId, String page, String type) {
        mModel.getPlayerLiset(actId, page, type);
    }

    @Override
    public void getPlayerListByTime(String actId, String playerId, String type) {
        mModel.getPlayerListByTime(actId,playerId,type);
    }

    @Override
    public void vote(int actId, String userName, Integer playerId) {
        mModel.vote(actId, userName, playerId);
    }

    @Override
    public void onVoteSuccess() {
        mView.onVoteSuccess();
    }

    @Override
    public void searchData(String actId, String text) {
        mModel.searchData(actId, text);
    }

    @Override
    public void onSearchSuccess(List<PlayerVOBean> data) {
        if (data == null || data.size() == 0) {
            mView.onSearchError("没有查询到相关信息");
        } else {
            mView.onSearchSuccess(data);
        }
    }
}
